#pragma once
#include <iostream>
#include <mysql/mysql.h>
#include <string>
#include <ctime>

// mysql的简单封装

class Connection
{
public:
    Connection();

    ~Connection();

    bool connect(std::string ip, unsigned short port, std::string user, std::string password, std::string dbname);

    //更新
    bool update(std::string sql);

    //查询
    MYSQL_RES *query(std::string sql);

    //刷新连接存活时间
    void refreshAliveTime() { _alivetime = clock(); }
    //返回存活时间
    clock_t getAliveTime() const { return clock() - _alivetime; }

private:
    MYSQL *_conn;

    clock_t _alivetime; //记录空闲状态后的存活时间
};